define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'pay/order/index',
                    add_url: '',
                    edit_url: '',
                    del_url: 'pay/order/del',
                    multi_url: 'pay/order/multi',
                    table: 'pay_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'uid', title: __('Uid'), formatter: Controller.api.formatter.uid},
                        {field: 'status', title: __('Status'),searchList: {"0":__('未支付'),"1":__('已支付')}, formatter: Controller.api.formatter.status},
                        {field: 'type', title: __('Type'),searchList: {"qqpay":__('QQ钱包'),"wxpay":__('微信'),"alipay":__('支付宝'),"tenpay":__('财付通')}, formatter: Controller.api.formatter.type},
                        {field: 'type_b', title: __('Type_b'),searchList: {"auth":__('官方'),"easy":__('易支付'),"ysh":__('易商户')}, formatter: Controller.api.formatter.type_b},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'realmoney', title: __('到账金额'), operate:'BETWEEN'},
                        {field: 'rate', title: __('费率'), operate:'BETWEEN'},
                        {field: 'trade_no', title: __('Trade_no')},
                        {field: 'out_trade_no', title: __('Out_trade_no')},
                        {field: 'title', title: __('Title'),operate: 'LIKE %...%'},
                        {field: 'domain', title: __('Domain')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'bd', title: __('补单'),  formatter: Controller.api.formatter.bd},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                showToggle: false,
                showColumns: false,
                showExport: false,
            });
			$(document).on("click", ".qzbd", function () {
                var id = $(this).data('id');
                Fast.api.ajax({
                    url: "pay/order/qzbd",
                    data: {"id":id},
                }, function (data, ret) {
                    $('.btn-refresh').click();
                    Fast.api.open(data.data, __('补单'));
                    return false;
                });
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            formatter: {
                type: function (value, row, index) {
                    return row.type_text;
                },
                type_b: function (value, row, index) {
                  	if(value == 'ysh') return '易商户';
                    return (value == 'easy' ? '易支付' : '官方');
                },
                status: function (value, row, index) {
                    return '<font color="'+(value == 0 ? 'red' : 'green')+'">'+row.status_text+'</font>';
                },
                uid: function (value, row, index) {
                    return (!value ? '无' : '<a data-original-title="用户信息（可编辑）" class="btn-execute btn-dialog" href="/admin/user/user/edit?ids='+value+'">'+value+'</a>');
                },
                bd: function (value, row, index) {
                    var html = ('<a style="border-radius:0px;" data-id="'+row.id+'" class="btn btn-xs btn-primary '+(row.status == 1 ? '' : 'qzbd')+'" '+(row.status == 1 ? 'target="_blank"' : '')+' href="'+(row.status == 1 ? value : 'javascript:;')+'">'+(row.status == 1 ? '补单' : '强制补单')+'</a>');
                	return html;
                },
            },
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});